/*
 * ThreadEnginePrime.cpp
 *
 *  Created on: Jan 27, 2013
 *      Author: Drew Prevost
 */

#include "ThreadEnginePrime.h"
#include "ThreadEngineSpin.h"

ThreadEnginePrime::ThreadEnginePrime(
                                      ThreadServoRate & threadServoExhaust,
                                      uint8_t nPinGlowPlug,
                                      uint8_t nPinGenConnect,
                                      uint8_t nPinStarterMotor,
                                      uint8_t nPinGenDisonnect,
                                      uint8_t nPinGenMonitor )
    : ThreadEngineBase( threadServoExhaust, nPinGlowPlug, nPinGenConnect, nPinStarterMotor, nPinGenDisonnect, nPinGenMonitor ),
      threadEngineSpin( threadServoExhaust, nPinGlowPlug, nPinGenConnect, nPinStarterMotor, nPinGenDisonnect, nPinGenMonitor )
{
}

ThreadEnginePrime::~ThreadEnginePrime()
{
}

bool ThreadEnginePrime::run()
{
  threadEngineSpin.run();
  threadMicroDelay.run();
  threadServoExhaust.run();

  PT_BEGIN()
  ;

  threadServoExhaust.setPosition( 180, 0 );
  PT_WAIT_UNTIL( threadServoExhaust.getPosition() == 180 );
  PT_SPAWN( threadEngineSpin );
  digitalWrite( nPinGlowPlug, HIGH );
  threadMicroDelay.setDelay( 5000000 );
  PT_SPAWN( threadMicroDelay );
  threadServoExhaust.setPosition( 0, 0 );
  PT_WAIT_UNTIL( threadServoExhaust.getPosition() == 0 );

PT_END()
;
return false;
}
